package com.example.demo.vo.common;

import com.github.pagehelper.Page;
import lombok.Data;

import java.util.List;

/**
 * 分页VO
 *
 * @param <T>
 */
@Data
public class PageVO<T> {
    private List<T> content;
    private PageInfoVO pageInfo;

    public static <PT, VT> PageVO<VT> convert(Page<PT> page, List<VT> voList) {
        PageVO<VT> vo = new PageVO<>();
        vo.setContent(voList);
        PageInfoVO infoVO = new PageInfoVO();
        infoVO.setPage(page.getPageNum());
        infoVO.setSize(page.getPageSize());
        infoVO.setOffset(page.getStartRow() + 1);
        infoVO.setTotal(page.getTotal());
        infoVO.setMaxPage(page.getPages());
        vo.setPageInfo(infoVO);
        return vo;
    }

    /**
     * 分页参数
     */
    @Data
    private static class PageInfoVO {
        private Integer page;
        private Integer size;
        private Integer offset;
        private Integer maxPage;
        private Long total;
    }
}
